package com.gemme.gemme.view;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.gemme.gemme.R;
import com.gemme.gemme.wode.FaPiaoTaitouActivity;
import com.gemme.gemme.wode.ShopOrderInvoice;

public class SIngleFapaiTaitouItemView extends RelativeLayout {
    private Context context;
    private ShopOrderInvoice bean;

    public SIngleFapaiTaitouItemView(Context context) {
        this(context,null);
    }

    public SIngleFapaiTaitouItemView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public SIngleFapaiTaitouItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        initView();
    }
    TextView tv_name;
    TextView tv_defaultType;
    TextView tv_taitoutype;
    TextView tv_eidt;
    private void initView() {
        LayoutInflater.from(context).inflate(R.layout.single_fapiao_taitou_view,this);

        tv_name = findViewById(R.id.tv_name);
        tv_defaultType = findViewById(R.id.tv_defaultType);
        tv_taitoutype = findViewById(R.id.tv_taitoutype);
        tv_eidt = findViewById(R.id.tv_eidt);
        tv_eidt.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {

                if(context instanceof Activity){
                    Activity act= (Activity)context;
                    Intent intent = new Intent(context, FaPiaoTaitouActivity.class);
                    if(bean != null)
                        intent.putExtra("data", JSON.toJSONString(bean));
                    act.startActivityForResult(intent,1);
                }

            }
        });
    }

    public void setData(ShopOrderInvoice bean) {
        this.bean = bean;
        tv_name.setText(bean.getInvoiceTitle());

        tv_defaultType.setVisibility(  bean.getDefaultType() == 0 ? VISIBLE : GONE);
        tv_taitoutype.setText(bean.getDefaultType() == 0 ? "个人抬头" : "公司抬头");
//        tv_eidt
    }

    public ShopOrderInvoice getData(){
        return bean;
    }

}
